<template>
	<view>
		<Header :showBack="true" title="我的优惠券" bgColor="#ace8f6"></Header>
		<view class="container">
			<view class="nav-box">
				<view class="item" :class="current == 1 ? 'on' : ''" @click="changeNav(1)">未使用</view>
				<view class="item" :class="current == 2 ? 'on' : ''" @click="changeNav(2)">已使用</view>
				<view class="item" :class="current == 3 ? 'on' : ''" @click="changeNav(3)">已失效</view>
			</view>
			<view class="box" v-if="couponList.length>0">
				<block v-for="(item, index) in couponList" :key="index">
					<view class="item flex-warp" :class="item.effective ? '' : 'lose-efficacy'">
						<image v-if="!item.effective" class="efficacy-logo" src="../../static/img/loseEfficacy_icon.png" mode=""></image>
						<view class="lt-content flex-warp">
							<view class="price-box">
								<view class="rmb">￥</view>
								<view class="price">{{ item.amount / 100 }}</view>
							</view>
							<view class="coupon-msg">
								<view class="coupon-title1">{{ item.stockName }}</view>
								<view class="coupon-name">满{{ item.limit / 100 }}元 立减{{ item.amount / 100 }}元</view>
								<view class="coupon-title2">有效期</view>
								<view class="coupon-time">{{ item.startTime }}至{{ item.endTime }}</view>
							</view>
						</view>
						<view class="rt-content">
							优
							<br />
							惠
							<br />
							券
						</view>
					</view>
				</block>
			</view>
			<view class="box empty-box" v-else>
				<image class="empty-img" src="../../static/img/icon_empty.png" mode=""></image>
				<view class="empty">暂无数据~</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			info: uni.getStorageSync('info'),
			limit: 999,
			page: 1,
			couponList: [],
			isQingqiu: false,
			current: 1
		};
	},
	onLoad(e) {
		this.getCouponList();
	},
	onReachBottom() {
		if (this.isQingqiu) {
			this.isQingqiu = false;
		}
	},
	methods: {
		changeNav(idx){
			if(this.current == idx){ return }
			this.couponList = [];
			this.current = idx
			this.getCouponList(idx)
		},
		getCouponList(usedFlag=1) {
			
			this.$http('/service/api/couponStock/getCouponList', {
					pageSize: this.limit,
					pageNum: this.page,
					condition: {
						memberId: this.info.id,
						usedFlag: usedFlag==3?1:usedFlag,
						// tenantId: this.info.tenantId,
						mode: 1
					}
				} ,res=>{
					
					if (res.data.statusCode == 200 && res.data.data.items.length > 0) {
						let arr = res.data.data.items.filter(col=>col.statusFlag !=3).map((items) => ({
							...items,
							startTime: items.startTime.slice(0, items.startTime.length - 3),
							endTime: items.endTime.slice(0, items.endTime.length - 3),
							effective: new Date(items.endTime.replace(/-/g,"/")).getTime() > Date.parse(new Date())? true : false
						}));
						this.couponList = this.couponList.concat(arr);
						if(usedFlag==3){
							this.couponList = this.couponList.filter(item=>!item.effective)
						}
					}
				
				})
			
		},
	}
};
</script>

<style scoped lang="less">
image,
view,
text {
	letter-spacing: normal;
}
.flex-warp {
	display: flex;
	align-items: center;
}
.tab {
	width: 100%;
	font-size: 30upx;
	color: #888888;
	top: 0;
	> view:first-child {
		display: flex;
		> view {
			width: 50%;
			height: 80upx;
			line-height: 80upx;
			text-align: center;
		}
		> view.active {
			color: #408f70;
		}
	}
	> view:last-child {
		width: 50%;
		height: 4upx;
		background-color: #408f70;
		transition: 0.1s all ease;
	}
}
.nav-box {
	width: 710rpx;
	margin: 0 20rpx;
	display: flex;
	align-items: center;
	padding: 6rpx;
	background: #ace8f6;
	border-radius: 40rpx;
	height: 68rpx;
	margin-bottom: 20rpx;
	margin-top: 20rpx;
	font-size: 24rpx;
	.item {
		flex: 1;
		color: #fff;
		text-align: center;
	}
	.item.on {
		background: #fff;
		color: #0022ab;
		border-radius: 40rpx;
		height: 56rpx;
		line-height: 56rpx;
	}
}
.box {
	width: 710rpx;
	padding-top: 20upx;
	padding-bottom: 40upx;
	background: #fff;
	border-radius: 16rpx;
	margin: 0 20rpx 20rpx;
	.item {
		// width: 650upx;
		width: 630upx;
		// height: 156upx;
		height: 165upx;
		// background-image: url('../../static/img/coupon_bg1.png');
		// background: #fff9f6;
		background-size: 100% 100%;
		margin: 20upx auto;
		color: #4e411f;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.lt-content {
			.price-box {
				display: flex;
				width: 125upx;
				height: 125upx;
				line-height: 125upx;
				justify-content: center;
				// margin-left: 13upx;
				margin-left: 14upx;
				// margin-right: 46upx;
				margin-right: 38upx;
				align-items: baseline;
				.price {
					font-size: 54upx;
					font-weight: bold;
					letter-spacing: -2upx;
				}
			}
			.coupon-msg {
				font-size: 26upx;
				width: 376upx;
				.coupon-name {
					font-size: 26upx;
					font-weight: bold;
					width: 100%;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
					color: #fb5830;
				}
				.coupon-title1 {
					margin-top: 20rpx;
					font-size: 26upx;
					font-weight: bold;
					width: 100%;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
					
				}
				.coupon-title2 {
					margin-top: 10rpx;
					font-size: 20upx;
					letter-spacing: initial;
				}
				.coupon-time {
					margin-bottom: 20upx;
					// font-size: 24upx;
					font-size: 20upx;
					letter-spacing: initial;
				}
			}
		}
		.rt-content {
			padding-right: 50upx;
			font-size: 26upx;
		}
	}
	.item.lose-efficacy {
		// background-image: url('../../static/img/coupon_bg2.png');
		position: relative;
		.efficacy-logo {
			position: absolute;
			right: 146upx;
			right: 85rpx;
			top: 24upx;
			top: 14upx;
			width: 100upx;
			height: 62upx;
			z-index: 999;
		}
	}
	view.button {
		width: 600upx;
		margin: 50upx auto;
		background-color: #19be6b;
		color: #ffffff;
		height: 80upx;
		line-height: 80upx;
		text-align: center;
		border-radius: 12upx;
	}
}
.empty-box{
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 174rpx;
	background: transparent;
	.empty-img{
		width: 360rpx;
		height: 360rpx;
		
	}
}
</style>
